package com.usian.controller;

import com.usian.pojo.TbContent;
import com.usian.pojo.TbContentCategory;
import com.usian.service.ContentService;
import com.usian.utils.AdNode;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 根据节点id查询商品内容信息
     *
     * @param id
     * @return
     */
    @RequestMapping("selectContentCategoryByParentId")
    public List<TbContentCategory> selectContentCategoryByParentId(@RequestParam Long id){
        return contentService.selectContentCategoryByParentId(id);
    }

    /**
     * 添加内容节点
     *
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("insertContentCategory")
    public Integer insertContentCategory(@RequestParam Long parentId,@RequestParam String name ){
        Integer num = contentService.insertContentCategory(parentId,name);
        return num;
    }

    /**
     * 删除节点
     *
     * @param categoryId
     * @return
     */
    @RequestMapping("deleteContentCategoryById")
    public Integer deleteContentCategoryById(@RequestParam Long categoryId){
        Integer num = contentService.deleteContentCategoryById(categoryId);
        return num;
    }


    /**
     *
     * 分页查询商品内容
     *
     * @param categoryId
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("selectTbContentAllByCategoryId")
    public PageResult selectTbContentAllByCategoryId(@RequestParam Long categoryId,
                                                     @RequestParam Integer page, @RequestParam Integer rows){
        PageResult pageResult = contentService.selectTbContentAllByCategoryId(categoryId,page,rows);
        return pageResult;
    }

    /**
     *
     * 添加商品内容
     *
     * @param tbContent
     * @return
     */
    @RequestMapping("insertTbContent")
    public Integer insertTbContent(@RequestBody TbContent tbContent){
        Integer num =contentService.insertTbContent(tbContent);
        return num;
    }

    /**
     * 根据id删除商品分类内容
     *
     * @param ids
     * @return
     */
    @RequestMapping("deleteContentByIds")
    public Integer deleteContentByIds(@RequestParam  Long ids){
        return contentService.deleteContentByIds(ids);
    }


    /**
     * 首页查询大广告
     *
     * @return
     */
    @RequestMapping("selectFrontendContentByAD")
    public List<AdNode> selectFrontendContentByAD(){
        return contentService.selectFrontendContentByAD();
    }


}
